#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    Dialog *dialog = new Dialog(this);

    connect(ui->push_button_01, &QPushButton::clicked, this, [dialog]() {
        dialog->show(); // 非模态
    });

    connect(ui->push_button_02, &QPushButton::clicked, this, [dialog]() {
        dialog->exec(); // 模态, 将阻塞程序执行
    });

    // 对话框 Accept 被点击后的事件
    connect(dialog, &QDialog::accepted, this, [=]() {
        qDebug() << "Accept Was Clicked!" << endl;
    });

    // 对话框 Rejected 被点击后的事件
    connect(dialog, &QDialog::rejected, this, [=]() {
        qDebug() << "Rejected Was Clicked!" << endl;
    });

    // 对话框 Done 被点击后的事件
    connect(dialog, &QDialog::finished, this, [=](int value) {
        qDebug() << "Done Was Clicked! " << "Value = " << value << endl;
    });
}

Widget::~Widget()
{
    delete ui;
}

